/*
 * ActivityChooserScreen.java
 *
 * Created on March 26, 2007, 3:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Activity;

import Experience.*;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.midlet.MIDlet;

/**
 *
 * @author dmgreen
 */
public class ActivityChooserScreen extends Form implements CommandListener, ItemStateListener {
    
    ChoiceGroup activityTypeCG;
   
    public final static String MEAL = "Meal";
    public final static String EXERCISE = "Exercise";
    public final static String OTHER = "Other";
    
    String curSelection = MEAL;
    
    private ExpUI myMIDlet = null; 
    
    private String[] activityTypes = new String[] {MEAL, EXERCISE, OTHER};
    
    /**
     * Creates a new instance of ActivityChooserScreen
     */
    public ActivityChooserScreen( MIDlet expsamp ) {
        super ("Choose Activity");
        
        System.out.println("1");
        myMIDlet = (ExpUI) expsamp;
        
        System.out.println("2");
        activityTypeCG = new ChoiceGroup("", Choice.POPUP, activityTypes, null);
                                                   
        System.out.println("3");
        this.append("Is this a:");
        this.append(activityTypeCG);
        this.setItemStateListener(this);
        
        System.out.println("4");
        
        this.addCommand(new Command("Next", Command.OK, 1));
        this.setCommandListener(this);
    }
 
    public void commandAction(Command com, Displayable dis) {
	String label = com.getLabel();
	
        if ("Next".equals(label)) {
            myMIDlet.notifyNext(getActivityType());
        }
    }

    public void itemStateChanged(Item item) {
        if (item == activityTypeCG) {
            int index = activityTypeCG.getSelectedIndex();
            curSelection = activityTypes[index];
        }
    }
    
    public String getActivityType() {
        return curSelection;
    }
}
